-
Notifications
You must be signed in to change notification settings - Fork 20
refactor: clean up reference tests #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @yyihuang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on a significant refactoring effort across the reference test suite. The core objective is to enhance the maintainability and readability of the tests by extracting common patterns and utilities into a dedicated Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request is a significant and valuable refactoring of the reference tests. It successfully centralizes the reference implementations into definition files and introduces a test_utils.py module to reduce code duplication across test files. This greatly improves the maintainability and clarity of the test suite. The changes are well-executed, but I've identified a critical issue in one of the refactored tests that needs to be addressed.
| sparse_indices = torch.randint( | ||
| 0, total_tokens_in_cache, (num_tokens, topk), dtype=torch.int32, device=device | ||
| 0, num_pages, (num_tokens, topk), dtype=torch.int32, device=device | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sparse_indices are being generated with an incorrect upper bound. For page_size=64, the reference implementation expects token-level indices, but torch.randint is being called with num_pages as the upper bound, which generates page-level indices. This will cause the test to use incorrect inputs, potentially leading to incorrect validation.
The upper bound should be the total number of tokens in the cache (num_pages * PAGE_SIZE).
| sparse_indices[t, :valid_count] = torch.randint( | ||
| 0, total_tokens_in_cache, (valid_count,), dtype=torch.int32, device=device | ||
| 0, num_pages, (valid_count,), dtype=torch.int32, device=device | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the issue in generate_random_inputs, the sparse_indices for the padding test are being generated with an incorrect upper bound. It should be the total number of tokens in the cache, not the number of pages. The reference implementation expects token-level indices when page_size > 1.
You should calculate total_tokens_in_cache = num_pages * PAGE_SIZE before the loop and use it as the upper bound for torch.randint here.
flashinfer_trace/tests/references/test_dsa_sparse_attention_h16_ckv512_kpe64_topk256_ps1.py: todo
flashinfer_trace/tests/references/test_dsa_sparse_attention_h16_ckv512_kpe64_topk256_ps64.py: todo
flashinfer_trace/tests/references/test_dsa_vs_definition_reference.py: todo
flashinfer_trace/tests/references/test_gdn_decode_qk16_v32_d128_k_last.py: ✅
flashinfer_trace/tests/references/test_gdn_prefill_qk16_v32_d128_k_last.py: ✅
flashinfer_trace/tests/references/test_gqa_paged_decode_h32_kv4_d128_ps1.py: ✅
flashinfer_trace/tests/references/test_gqa_paged_decode_h32_kv4_d128_ps64.py: ✅
flashinfer_trace/tests/references/test_gqa_paged_decode_h32_kv8_d128_ps1.py: ✅
flashinfer_trace/tests/references/test_gqa_paged_decode_h32_kv8_d128_ps64.py: ✅
flashinfer_trace/tests/references/test_gqa_paged_prefill_h32_kv4_d128_ps1.py: todo